class Solution {
public:
    int maximumEnergy(vector<int>& a, int k) {
        int n = a.size(), ans = INT_MIN;
        vector<int> dp(n);
        for (int i = n - 1; i >= 0; i--) {
            dp[i] = a[i];
            if (i < n - k) dp[i] += dp[i + k];
            ans = max(ans, dp[i]);
        }
        return ans;
    }
};